<template>
  <el-table :data="tableData" style="width: 100%" v-loading="loading" :highlight-current-row="true" :stripe="true" size="mini">
    <template v-for="item in tableHeader">
      <el-table-column
        v-if="item.prop !== ''"
        :prop="item.prop"
        :label="item.label">
      </el-table-column>
      <el-table-column
        v-if="item.prop === 'UpdateAgent'"
        :label="item.label">
        <template scope="scope">
          <agent
            :id="scope.row.UpdateAgent"
            :isNum="true"
          ></agent>
        </template>
      </el-table-column>
      <el-table-column
        v-if="item.prop === ''"
        :label="item.label">
        <template scope="scope">
          <el-button @click="updata(scope.row)" type="text" size="small" class="updata">{{$t('public.edit')}}</el-button>
          <el-button type="text" @click="del(scope.row)" size="small" class="del">{{$t('public.delete')}}</el-button>
        </template>
    </el-table-column>
    </template>
  </el-table>
</template>
<script>
  import Agent from '@/components/public-modules/cache/Agent'
  export default {
    name: 'WeiboTable',
    data () {
      return {
        currentDeleteData: {}
      }
    },
    props: {
      tableData: Array,
      tableHeader: Array,
      loading: {
        type: Boolean,
        default: false
      }
    },
    methods: {
      updata (val) {
        this.$emit('updata', val)
      },
      del (val) {
        this.$confirm(this.$t('config.channel.sureDeleteWeibo'), this.$t('public.tip'), {
          confirmButtonText: this.$t('public.confirm'),
          cancelButtonText: this.$t('public.cancel'),
          cancelButtonClass: 'primary_btn',
          confirmButtonClass: 'primary_btn',
          type: 'warning'
        }).then(() => {
          this.currentDeleteData = val
          this.deleteWeibo()
        }).catch(() => {
          console.log('取消')
        })
      },
      deleteWeibo () {
        let data = {}
        if (this.currentDeleteData && this.currentDeleteData._id) {
          data._id = this.currentDeleteData._id
        }
        this.$store.dispatch('remvoeWeiboConfig', data).then(resp => {
          if (resp.success) {
            this.$emit('resh')
            this.$message.success(this.$t('sms.successDel'))
          } else {
            this.$message.error(this.$t('sms.failDel'))
          }
        })
      }
    },
    components: {
      Agent
    }
  }
</script>
<style lang="stylus" scoped>
  @import "../../../../../assets/common.styl"
  .updata
    cursor pointer
  .el-table .cell >.el-button--text.del
    color $c-pink
    cursor pointer
</style>
